<template>
    <el-table :data="orders" style="width: 100%;padding-top: 15px;">
        <el-table-column label="交易订单号" show-overflow-tooltip>
            <template slot-scope="scope">
                {{scope.row.tradeNo}}
            </template>
        </el-table-column>
        <el-table-column label="订单时间" width="200" align="center">
            <template slot-scope="scope">
                {{scope.row.createTime}}
            </template>
        </el-table-column>
        <el-table-column label="订单金额" width="195" align="center">
            <template slot-scope="scope">
                ¥{{scope.row.totalPrice/100}}
            </template>
        </el-table-column>
        <el-table-column label="订单状态" width="100" align="center">
            <template slot-scope="scope">
                <el-tag> {{scope.row.status ===0 ? '进行中':'已完成' }}</el-tag>
            </template>
        </el-table-column>
    </el-table>
</template>

<script>
import { parseTime } from '../../../../utils';
export default {
    data() {
        return {
            orders: null
        };
    },
    mounted() {
        const orders = sessionStorage.getItem('DashBoardOrders');
        if (orders) {
            this.orders = JSON.parse(orders);
        } else {
            this.$ajax.get('/dashBoard/orders').then(res => {
                this.orders = res.data.map(item => {
                    item.createTime = parseTime(item.createTime);
                    return item;
                });
                sessionStorage.setItem(
                    'DashBoardOrders',
                    JSON.stringify(this.orders)
                );
            });
        }
    }
};
</script>
